package com.hyh.music.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hyh.music.Result.PageResult;
import com.hyh.music.constant.MessageConstant;
import com.hyh.music.domain.domainDTO.SongListDTO;
import com.hyh.music.domain.domainDTO.MessagePageDTO;
import com.hyh.music.domain.domains.ListSong;
import com.hyh.music.domain.domains.SongList;
import com.hyh.music.mapper.ListSongMapper;
import com.hyh.music.mapper.SongListMapper;
import com.hyh.music.service.SongListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@SuppressWarnings({"all"})
@Service
public class SongListServiceImpl implements SongListService {


    @Autowired
    SongListMapper songListMapper;

    @Autowired
    ListSongMapper listSongMapper;


    /**
     * 歌单的分页查询
     *
     * @param songListDTO
     * @return
     */
    @Override
    public PageResult Page(MessagePageDTO messagePageDTO) {
        PageHelper.startPage(messagePageDTO.getPage(), messagePageDTO.getPageSize());
        Page<SongList> page = songListMapper.Page(messagePageDTO);
        List<SongList> result = page.getResult();
        long total = page.getTotal();
        PageResult result1 = new PageResult();
        result1.setRecodes(result);
        result1.setTotal(total);
        return result1;
    }
    /**
     * 添加歌单
     * @param songListDTO
     */
    @Override
    public void addSongList(SongListDTO songListDTO) {
        songListMapper.add(songListDTO);
    }

    /**
     * id查歌单
     * @param id
     * @return
     */
    @Override
    public SongList selectById(Integer id) {
        SongList songList =  songListMapper.selectById(id);
        return songList;
    }

    /**
     * 更新歌单
     * @param songList
     */
    @Override
    public void update(SongList songList) {
        songListMapper.update(songList);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public int deleteById(Integer id) {
        List<ListSong> listSongs = listSongMapper.selectById(id);
        if (listSongs.size() != 0 && listSongs != null){
            return MessageConstant.FINAL;
        }
        else {
            songListMapper.delete(id);
            return MessageConstant.SUCCESS;
        }
    }
}
